

package edu.uoc.tds.common;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class UtilLenguaje  {
	private static ResourceBundle resourceBundle;
	private static String currentBaseName;
	private static Locale currentLocale;

	

	public static synchronized boolean setDefaultLanguage(String baseName) {
		try {
			currentBaseName=baseName;
			resourceBundle = ResourceBundle.getBundle(baseName,Locale.getDefault());
			return true;
		}catch(MissingResourceException e){
			return false;
		}
	}

	
	public static synchronized boolean setLanguage(String baseName, Locale locale) {
		try {
			currentBaseName=baseName;
			currentLocale=locale;
			resourceBundle = ResourceBundle.getBundle(baseName,locale);
			return true;
		}catch(MissingResourceException e){
			return false;
		}
	}

	

	public static String getMessage(String key)  {
		try {
			return resourceBundle.getString(key);
		}catch(MissingResourceException e) {
			return new String();
		}
	}

	
	public static String getCurrentBaseName() {
		return currentBaseName;
	}

	
	public static Locale getCurrentLocale() {
		return currentLocale;
	}

}
